﻿using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Identity.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class updatepermissionbindingsName : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_PermissionKeyResourceIds_Permissions_permissionId",
                table: "PermissionKeyResourceIds");

            migrationBuilder.DropPrimaryKey(
                name: "PK_PermissionKeyResourceIds",
                table: "PermissionKeyResourceIds");

            migrationBuilder.RenameTable(
                name: "PermissionKeyResourceIds",
                newName: "ApiPermissionBindings");

            migrationBuilder.RenameIndex(
                name: "IX_PermissionKeyResourceIds_ResourceId_FromServiceName",
                table: "ApiPermissionBindings",
                newName: "IX_ApiPermissionBindings_ResourceId_FromServiceName");

            migrationBuilder.RenameIndex(
                name: "IX_PermissionKeyResourceIds_permissionId",
                table: "ApiPermissionBindings",
                newName: "IX_ApiPermissionBindings_permissionId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_ApiPermissionBindings",
                table: "ApiPermissionBindings",
                column: "ResourceId");

            migrationBuilder.AddForeignKey(
                name: "FK_ApiPermissionBindings_Permissions_permissionId",
                table: "ApiPermissionBindings",
                column: "permissionId",
                principalTable: "Permissions",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_ApiPermissionBindings_Permissions_permissionId",
                table: "ApiPermissionBindings");

            migrationBuilder.DropPrimaryKey(
                name: "PK_ApiPermissionBindings",
                table: "ApiPermissionBindings");

            migrationBuilder.RenameTable(
                name: "ApiPermissionBindings",
                newName: "PermissionKeyResourceIds");

            migrationBuilder.RenameIndex(
                name: "IX_ApiPermissionBindings_ResourceId_FromServiceName",
                table: "PermissionKeyResourceIds",
                newName: "IX_PermissionKeyResourceIds_ResourceId_FromServiceName");

            migrationBuilder.RenameIndex(
                name: "IX_ApiPermissionBindings_permissionId",
                table: "PermissionKeyResourceIds",
                newName: "IX_PermissionKeyResourceIds_permissionId");

            migrationBuilder.AddPrimaryKey(
                name: "PK_PermissionKeyResourceIds",
                table: "PermissionKeyResourceIds",
                column: "ResourceId");

            migrationBuilder.AddForeignKey(
                name: "FK_PermissionKeyResourceIds_Permissions_permissionId",
                table: "PermissionKeyResourceIds",
                column: "permissionId",
                principalTable: "Permissions",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);
        }
    }
}
